package com.lovo.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j(topic = "test")
public class LogAspect {
    @Pointcut("execution(* com.lovo..*(..))")
    public void logPointcut(){
        System.out.println("这个方法调用吗?     /n不调用");
    }

    @Before("logPointcut()")
    public void sayHello(JoinPoint joinPoint){
        log.debug("Hello："+joinPoint.getSignature());
    }
    @After("logPointcut()")
    public void sayBye(JoinPoint joinPoint){
        log.debug("bye："+joinPoint.getSignature()+"\n");
    }
    @AfterThrowing("logPointcut()")
    public void sayError(JoinPoint joinPoint){
        log.error("Error："+joinPoint.getSignature());
    }
//    @Around("execution(* com.lovo.service..*(..))")
//    public Object sayAround(ProceedingJoinPoint joinPoint){
//        long beforeTime = System.currentTimeMillis();
//        log.debug("进入方法："+joinPoint.getSignature());
//        Object obj = null;
//        try {
//            obj = joinPoint.proceed(joinPoint.getArgs());
//        } catch (Throwable throwable) {
//            throwable.printStackTrace();
//            log.error("抛出异常："+joinPoint.getSignature());
//        }
//        log.debug("退出方法："+joinPoint.getSignature()+
//                "执行时间为:"+
//                (System.currentTimeMillis()-beforeTime)+
//                "毫秒\n");
//
//        return obj;
//    }
}
